package com.itheima.app.controller;

import com.itheima.app.manager.PhoneNumberManager;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PhoneNumberController {
    @Autowired
    private PhoneNumberManager phoneNumberManager;

    public PhoneNumberController() {
    }

    //修改手机号- 1 发送短信验证码
    @PostMapping("/users/phone/sendVerificationCode")
    public void sendVerificationCode() {
        phoneNumberManager.sendVerificationCode();
    }

    //修改手机号 - 2 校验验证码
    @PostMapping("/users/phone/checkVerificationCode")
    public Map<String, Boolean> checkVerificationCode(@RequestBody Map<String, String> map) {
        //得到map中的数据
        String verificationCode = map.get("verificationCode");
        return phoneNumberManager.checkVerificationCode(verificationCode);
    }

    //修改手机号 - 3 保存
    @PostMapping("/users/phone")
    public void saveNewPhoneNumber(@RequestBody Map<String, String> map) {
        //获得map中的数据
        String phone = map.get("phone");
        phoneNumberManager.saveNewPhoneNumber(phone);
    }
}
